<div class="row">
  <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal2">
    设置被考核部门
  </button>

  <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
    设置被考核人
  </button>
</div>
<div class="row">
  <div class="panel panel-success">
    <div class="panel-heading">
      <h3 class="panel-title">岗位名称：<%=@position.name%></h3>
    </div>
    <div class="panel-body">
      <div class="row">
        <div class="col-md-6"><h4>岗位描述:</h4><%=@position.desc%></div>
        <div class="col-md-6"><h4>岗位权重:</h4><%=@position.weight%></div>
      </div>
    </div>
  </div>
</div>
<div class="bs-example" data-example-id="bordered-table">
  <h4>本岗位员工列表</h4>
  <table class="table table-bordered">
    <thead>
      <tr>
        <th>id</th>
        <th>员工姓名</th>
        <th>级别</th>
        <th>得分</th>
      </tr>
    </thead>
    <tbody>
      <% @employees.each do |employee| %>
        <tr>
          <th scope="row"><%=employee.id%></th>
          <td><%=employee.name%></td>
          <td><%=employee.level%></td>
          <td><%=employee.score%></td>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>

  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="myModalLabel">设置被考核人</h4>
        </div>
        <div class="modal-body">
          <select id="test-select" multiple="multiple">
            <% for i in @all_employees %>
              <% if i["employee_select"] == 1 %>
                <option value="<%=i["employee_id"]%>" data-section="<%=i["employee_position"]%>" selected="selected"><%=i["employee_name"]%></option>
              <% else %>
                <option value="<%=i["employee_id"]%>" data-section="<%=i["employee_position"]%>" ><%=i["employee_name"]%></option>
              <% end %>
            <% end %>
          </select>
        </div>
        <div class="modal-footer">
          <button type="button" id = "employee_close" class="btn btn-default" data-dismiss="modal">关闭</button>
          <button type="button" id = "employee_save" class="btn btn-primary">保存</button>
        </div>
      </div>
    </div>
  </div>

  <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="myModalLabel">设置被考核部门</h4>
        </div>
        <div class="modal-body">
          <select id="test-select2" multiple="multiple">
            <% for i in @all_teams %>
              <% if i["team_select"] == 1 %>
                <option value="<%=i["team_id"]%>" data-section="" selected="selected" ><%=i["team_name"]%></option>
              <%else%>
                <option value="<%=i["team_id"]%>" data-section=""><%=i["team_name"]%></option>
              <%end%>

            <% end %>
          </select>
        </div>
        <div class="modal-footer">
          <button type="button" id = "team_close" class="btn btn-default" data-dismiss="modal">关闭</button>
          <button type="button" id = "team_save" class="btn btn-primary">保存</button>
        </div>
      </div>
    </div>
  </div>
  <div class="bs-example" data-example-id="bordered-table">
    <h4>员工评分密码条</h4>
    <table class="table table-bordered">
      <thead>
        <tr>
          <th>密码条内容</th>
          <th>是否使用</th>
          <th>使用时间</th>
        </tr>
      </thead>
      <tbody>
        <% @licenses_employee.each do |l_e| %>
          <tr>
            <th scope="row"><%=l_e.content%></th>
            <%if l_e.is_used ==1 %>
              <td>是</td>
              <td><%=l_e.updated_at%></td>
            <%else%>
              <td>否</td>
              <td></td>
            <%end%>
          </tr>
        <% end %>
      </tbody>
    </table>
  </div>
  <div class="bs-example" data-example-id="bordered-table">
    <h4>部门评分密码条</h4>
    <table class="table table-bordered">
      <thead>
        <tr>
          <th>密码条内容</th>
          <th>是否使用</th>
          <th>使用时间</th>
        </tr>
      </thead>
      <tbody>
        <% @licenses_team.each do |l_t| %>
          <tr>
            <th scope="row"><%=l_t.content%></th>
            <%if l_t.is_used ==1 %>
              <td>是</td>
              <td><%=l_t.updated_at%></td>
            <%else%>
              <td>否</td>
              <td></td>
            <%end%>
          </tr>
        <% end %>
      </tbody>
    </table>
  </div>
<script type="text/javascript">
  var tree1 = $("#test-select").treeMultiselect({ enableSelectAll: true, sortable: true });
  var tree2 = $("#test-select2").treeMultiselect({ enableSelectAll: true, sortable: true });
  $(document).ready(function(){
    $("#team_save").click(function() {
      var team_selected_list = new Array();
      $("#myModal2").find(".selected").children().each(function(){
        team_selected_list.push($(this).attr("data-value"))
      });
      $.post( "/teams/team_relation_save", {team_selecteds: team_selected_list, position_id: "<%=@position.id%>"}, function(data) {
        $("#team_close").click();
      });
    })
  });
  $(document).ready(function(){
    $("#employee_save").click(function() {
      var employee_selected_list = new Array();
      $("#myModal").find(".selected").children().each(function(){
        employee_selected_list.push($(this).attr("data-value"))
      });
      $.post( "/teams/employee_relation_save", {employee_selecteds: employee_selected_list, position_id: "<%=@position.id%>"}, function(data) {
        $("#employee_close").click();
      });
    })
  });
</script>
